﻿/*
 * 可任意输入m与n值，实现一个 m*n 二维数组的转置矩阵
 */

int M,N,row,col;
string strM;
string strN;
string tempstr;
Console.WriteLine("[输入M*N矩阵的维数]");
Console.Write("请输入维数：");
strM = Console.ReadLine(); 
M = int.Parse(strM); 

Console.Write("请输入维度N：");
strN = Console.ReadLine(); 
N = int.Parse(strN); 

int [,] arrA = new int[M,N];
int[,] arrB = new int [N, M];
Console.WriteLine("请输入矩阵内容：");
for (row = 1; row <= M; row++)
{
 for (col = 1; col <= N; col++)
 {
  Console.Write("a"+row + col +"=");
  tempstr = Console.ReadLine();
  arrA[row - 1, col - 1] = int.Parse(tempstr);
 }
}

Console.WriteLine("输入矩阵内容为\n");
for (row = 1; row <= M; row++)
{
 for (col = 1; col <= N; col++)
 {
  Console.Write(arrA[(row -1),(col -1)]);
  Console.Write("\t");
 }
 Console.WriteLine();
}

// 进行矩阵转置的操作
for (row = 1; row <= N; row++)
{
 for (col = 1; col <= M; col++)
 {
  arrB[(row -1),(col -1)]=arrA[(col -1),(row -1)]; 
 }
}

Console.WriteLine("转置矩阵内容为");
for (row = 1; row <= N; row++)
{
 for (col = 1; col <= M; col++)
 {
  Console.Write(arrB[(row -1),(col -1)]);
  Console.Write("\t");
 }

 Console.ReadLine();
}

Console.ReadKey();

